<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>箭头函数(函数的简写)</title>
</head>
<body>
<script>
    //函数只有一个参数的时候
    let a = function (obj) {
        console.log(obj)
    };
    a(300);
    //简写为
    let b = obj => console.log(obj);
    b(400);

    //函数的参数有多个的时候
    let print = function (x, y) {
        return x + y;
    };
    console.log(print(100, 200));

    //简写为
    let print2 = (m, n) => m + n;
    console.log(print2(2000, 200))

    //代码不止一行的时候可以使用{}括起来
    let print3 = (c, d) => {
        return c + d;
    };
    console.log(print3(20001, 22))


    //对象的函数属性简写

    let person = {
        name: "jack",
        // 以前：
        eat: function (food) {
            console.log(this.name + "在吃" + food);
        },
        //简写1
        eat2: food => console.log(perosn.name + "在吃" + food),
        //简写2
        eat3(food){
            console.log(this.name+ "在吃" + food)
        }

    }

</script>
</body>
</html>